const nodemailer = require('nodemailer')
const config = think.config('email')
if (config) {
  const transporter = nodemailer.createTransport(config)
  /**
   *
   * @param to
   * @param subject
   * @param content
   * @param isHtml
   * @param isDebug
   * @example yy.email.sendMail(邮箱地址`,`号隔开,主题,内容)
   */
  const sendMail = (to, subject, content, isHtml = false, isDebug = true) => {
    const o = {from: `"noreply" <ckken@qq.com>`, to: to, subject: subject, text: content}
    if (isHtml) {
      o.html = content
    } else {
      o.text = content
    }
    transporter.sendMail(o, (e, d) => {
      isDebug && yy.log.debug(e, d)
    })
  }
  module.exports = {
    transporter, sendMail
  }
}
